<template>
    <div class="app-container">
        <!--项目数据信息弹窗 -->
        <el-dialog :title="this.title" :visible="open" @close="cancel" width="1150px"
         :close-on-click-modal="false" :close-on-press-escape="false"
          append-to-body>
          <el-form ref="form" :model="form" :inline="true" :rules="rules" label-width="100px">
            <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix">
                  <span style="font-size:16px;font-weight: bold;">项目信息</span> 
                </div>
                <div   class="text item">
                    <el-form-item label="项目编码" prop="projectNo">
                        <el-input v-model="form.projectNo"  placeholder="请输入选择编码" style="width:170px"/><i class="el-icon-search" style="font-size:26px;margin-left:5px;cursor:pointer;" @click="openProject"></i>
                    </el-form-item>
                    <el-form-item label="机型" prop="model">
                        <el-input v-model="form.model" placeholder="请输入机型" />
                    </el-form-item>
                    <el-form-item label="专案类别" prop="level">
                        <el-select filterable clearable v-model="form.level" placeholder="请选择专案类别">
                        <el-option v-for="dict in dict.type.project_level" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                    </el-form-item>
                    <el-form-item label="芯片组" prop="chipGroup">
                        <el-input v-model="form.chipGroup" placeholder="请输入芯片组" />
                    </el-form-item>
                    <el-form-item label="AD板" prop="adBoard">
                        <el-input v-model="form.adBoard" placeholder="请输入AD板" />
                    </el-form-item>
                    <el-form-item label="LCM/OC" prop="lcmOc">
                        <el-input v-model.number="form.lcmOc" placeholder="请输入LCM/OC" />
                    </el-form-item>
                    <el-form-item label="电源/适配器" class="labelword" prop="powerSupply">
                        <el-input v-model="form.powerSupply" placeholder="请输入电源/适配器" />
                    </el-form-item>
                    <el-form-item label="恒流板" prop="currentBoard">
                        <el-input v-model="form.currentBoard" placeholder="请输入恒流板" />
                    </el-form-item>
                    <el-form-item label="Arm板" prop="armBoard">
                        <el-input v-model="form.armBoard" placeholder="请输入Arm板" />
                    </el-form-item>
                    <el-form-item label="其他" prop="other">
                        <el-input v-model="form.other" placeholder="请输入其他" />
                    </el-form-item>
                    <el-form-item label="客户" prop="custom">
                        <el-input v-model="form.custom" placeholder="请输入客户" />
                    </el-form-item>
                    <el-form-item label="差异说明" prop="remark">
                        <el-input type="textarea" v-model="form.remark" placeholder="请输入项目差异说明" />
                    </el-form-item>
                    <el-form-item label="修改说明" prop="descritions">
                        <el-input type="textarea" v-model="form.descritions" placeholder="请输入项目差异说明" />
                    </el-form-item>
                    
                </div>
              </el-card>

               <el-card class="box-card" shadow="never" style="margin-top:20px">
                <div slot="header" class="clearfix">
                  <span style="font-size:16px;font-weight: bold;">项目成员</span> 
                </div>
                <div   class="text item">
                    <el-form-item label="项目经理" prop="pjManage">
                        <el-input v-model="form.pjManage" placeholder="请输入项目经理" />
                    </el-form-item>
                    <el-form-item label="硬件电子" prop="hardElectron">
                        <el-input v-model="form.hardElectron" placeholder="请输入电子工程师" />
                    </el-form-item>
                    <el-form-item label="硬件电源" prop="hardPower">
                        <el-input v-model="form.hardPower" placeholder="请输入电源工程师" />
                    </el-form-item>
                    <el-form-item label="光学" prop="optics">
                        <el-input v-model="form.optics" placeholder="请输入光学工程师" />
                    </el-form-item>
                    <el-form-item label="软件" prop="software">
                        <el-input v-model="form.software" placeholder="请输入软件工程师" />
                    </el-form-item>
                    <el-form-item label="结构" prop="structure">
                        <el-input v-model="form.structure" placeholder="请输入结构工程师" />
                    </el-form-item>
                    <el-form-item label="NPI" prop="npi">
                        <el-input v-model="form.npi" placeholder="请输入npi" />
                    </el-form-item>
                    <el-form-item label="App" prop="app">
                        <el-input v-model="form.app" placeholder="请输入app负责人" />
                    </el-form-item>
                    <el-form-item label="Touch" prop="touch">
                        <el-input v-model="form.touch" placeholder="请输入Touch负责人" />
                    </el-form-item>
                </div>
              </el-card>
          </el-form>
           
            <div slot="footer" class="dialog-footer" v-if="buttonView">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>



        <el-dialog title="选择项目" :visible="visible" @close="cancelProject" width="700px">
            <el-table border v-loading="loading" :data="projectList" style="margin-top:10px" @row-click="handleCurrentChange">
                <el-table-column label="选择" width="80">
                    <template slot-scope="scope">
                        <el-radio class="radio" :label="scope.row.id" >{{""}}</el-radio>
                    </template>
                  </el-table-column>
                <el-table-column label="项目编码" align="center" prop="projectNo" />
                <el-table-column label="项目名称" align="center" prop="projectName" />
                <el-table-column label="项目经理" align="center" prop="projectManagerName" />
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getProjectList" />
        </el-dialog>

    </div>
</template>
  
<script>
import { addProject, updateProject, getProjectDetail } from "@/api/business/project";
import { queryProjectListNoBug,getDetail } from "@/api/projectManage/projectList";
import { getUserByPostCode,getUsersByRolekey } from "@/api/system/user";
export default {
    name: 'ProjectForm',
    dicts:['project_level'],
    props: {
        open: {
            type: Boolean,
            default: false,
        },
        title: {
            type: String,
            default: '',
        },
        isUpdate: {
            type: Boolean,
            default: false,
        },
    },
    data() {
       
        return {


            //弹框是否可见
            visible:false,
            loading:false,
            //总数
            total:0,
            //项目列表
            projectList:[],

            //项目成员列表
            projectMemberList:[],

            buttonView: true,
            pjmList: [],
            hardEList: [],
            hardPList: [],
            opticsList: [],
            softList: [],
            stuList: [],
            NPIList: [],
            form: {},//表单数据对象
            queryParams:{
                pageSize:10,
                pageNum:1,
                projectNo:null
            },
            rules: {

                model: [
                    { required: true, message: "机型不能为空", trigger: "blur" }
                ],
                projectNo: [
                    { required: true, message: "项目编码不能为空", trigger: "blur" }
                ],
                level: [
                    { required: true, message: "专案类别不能为空", trigger: "blur" }
                ],
                chipGroup: [
                    { required: true, message: "芯片组不能为空", trigger: "blur" }
                ],
                adBoard: [
                    { required: true, message: "AD板不能为空", trigger: "blur" }
                ],
                lcmOc: [
                    { required: true, message: "lcmOc不能为空", trigger: "blur" }
                ],
                powerSupply: [
                    { required: true, message: "电源/适配器不能为空", trigger: "blur" }
                ]
                // hardPower: [
                //     { required: true, message: "硬件电源工程师不能为空", trigger: "blur" }
                // ],
                // hardElectron: [
                //     { required: true, message: "硬件电子工程师不能为空", trigger: "blur" }
                // ],
                // pjManage: [
                //     { required: true, message: "项目经理不能为空", trigger: "blur" }
                // ],
                // optics: [
                //     { required: true, message: "光学工程师不能为空", trigger: "blur" }
                // ],
                // software: [
                //     { required: true, message: "软件工程师不能为空", trigger: "blur" }
                // ],
                // structure: [
                //     { required: true, message: "结构工程师不能为空", trigger: "blur" }
                // ],
            },
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now();
                },
            },
        }
    },
    created() {
        
    },
    mounted() {

    },
    methods: {

        handleCurrentChange(row){
            this.visible = false;
            this.queryParams = {};
            getDetail(row.id).then(response =>{ 
                this.form.projectNo   = response.data.projectNo;
                this.form.level   = response.data.level;
          })
        },


 

        //取消选择项目
        cancelProject(){
            this.visible = false; 
        },

                //取消选择项目
        openProject(){
            this.visible = true; 
            this.getProjectList();
        },

        getProjectList(){
            this.loading = true;
            queryProjectListNoBug(this.queryParams).then(response=>{
                    this.projectList  = response.rows;
                    this.total = response.total;
                    this.loading = false;
            })

        },



        showHiddle() {
            this.buttonView = false
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                custome: null,
                model: null,
                projectNo: null,
                level: null,
                chipGroup: null,
                adBoard: null,
                lcmOc: null,
                powerSupply: null,
                currentBoard: null,
                armBoard: null,
                remark: null,
                descritions: null,
                //项目成员参数
                pjManage: null,
                hardElectron: null,
                hardPower: null,
                optics: null,
                software: null,
                structure: null,
                npi: null,
                app: null,
                touch: null,
            };
            this.resetForm("form");
        },
        // 取消按钮
        cancel() {
            this.reset();
            this.open = false;
            this.$emit("close");
        },
        /**新建项目按钮 */
        submitForm() {
            this.buttonView=false
            this.$refs["form"].validate(valid => {
                let flag=false
                if (valid) {
                    // const map=new Map()
                    // map.set(this.$store.state.globalParam.PJM,this.form.pjm)
                    // map.set(this.$store.state.globalParam.HARD,this.form.hard)
                    // map.set(this.$store.state.globalParam.OPTICS,this.form.optics)
                    // map.set(this.$store.state.globalParam.SOFT,this.form.soft)
                    // map.set(this.$store.state.globalParam.NPI,this.form.NPI)
                    // this.form.map=map
                    // console.log(this.form);
                    flag=true
                    this.$modal.loading("正在处理请稍等....")
                    if (this.form.id) {
                        updateProject(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功")
                            this.$emit('updateList')
                            this.reset()
                            this.$modal.closeLoading()
                            this.$emit("close");
                            this.buttonView = true
                        }).catch(
                                ()=>{
                                    this.buttonView = true  
                                }
                            );
                        this.$modal.closeLoading()
                    } else {
                        addProject(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功")
                            this.$emit('updateList')
                            this.reset()
                            this.$modal.closeLoading()
                            this.$emit("close");
                            this.buttonView = true
                        }).catch(
                                ()=>{
                                    this.buttonView = true  
                                }
                            );
                        this.$modal.closeLoading()
                    }
                }
                if(!flag){
                    this.buttonView = true
                }
            });
        },
        getRdUserList(){
            getUsersByRolekey(this.$store.state.globalParam.RDROLE).then(result=>{
                this.pjmList = result.data
                this.hardEList = result.data
                this.hardPList = result.data
                this.softList = result.data
                this.opticsList = result.data
                this.stuList = result.data
            })
        },
        getNpiList(){
            getUsersByRolekey(this.$store.state.globalParam.NPI).then(result=>{
                this.NPIList = result.data
            })
        },
        /**
         * 获取项目经理列表
         */
        getPjmUserList() {
            getUserByPostCode(this.$store.state.globalParam.PJM).then(result => {
                this.pjmList = result.data
            })
        },
        /**
         * 获取硬件电子工程师列表
         */
        getHardEUserList() {
            getUserByPostCode(this.$store.state.globalParam.HARDE).then(result => {
                this.hardEList = result.data
            })
        },
        /**
         * 获取硬件电源工程师列表
         */
        getHardPUserList() {
            getUserByPostCode(this.$store.state.globalParam.HARDP).then(result => {
                this.hardPList = result.data
            })
        },
        /**
        * 获取软件工程师列表
        */
        getSoftUserList() {
            getUserByPostCode(this.$store.state.globalParam.SOFT).then(result => {
                // console.log(result)
                this.softList = result.data
            })
        },
        /**
        * 获取光学工程师列表
        */
        getOpticsUserList() {
            getUserByPostCode(this.$store.state.globalParam.OPTICS).then(result => {
                this.opticsList = result.data
            })
        },
        /**
        * 获取结构工程师列表
        */
        getStuUserList() {
            getUserByPostCode(this.$store.state.globalParam.STU).then(result => {
                this.stuList = result.data
            })
        },
        /**
        * 获取工厂NPI列表
        */
        getNPIUserList() {
            getUserByPostCode(this.$store.state.globalParam.NPI).then(result => {
                this.NPIList = result.data
            })
        },
        //获取项目详情
        getProjectBYId(id) {
            getProjectDetail(id).then(result => {
                this.form = result.data
            })
        },
        //onClose () {
        //     //重置表单
        //     this.reset();
        //     this.open = false
        // },
    }
}
</script>
  
<style lang="scss" scoped>
.el-col {
    height: 60px;
}

.labelword ::v-deep .el-form-item__label {
    white-space: pre-line !important;
    line-height: 15px !important;
    
}
</style>
  